package com.music.service.urls.service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Required;

import com.music.service.urls.beans.Url;
import com.music.service.urls.dao.UrlDAO;

public class UrlServiceImpl implements UrlService {

	private UrlDAO mUrlDAO;

	public List<Url> getUrlsOfSong(Long pSongId) {
		return getUrlDAO().getUrlsOfSong(pSongId);
	}

	public Url addNewUrl(Url pUrl) {
		return getUrlDAO().addNewUrl(pUrl);
	}

	/**
	 * @return the urlDAO
	 */
	public UrlDAO getUrlDAO() {
		return mUrlDAO;
	}

	/**
	 * @param pUrlDAO
	 *            the urlDAO to set
	 */
	@Required
	public void setUrlDAO(UrlDAO pUrlDAO) {
		mUrlDAO = pUrlDAO;
	}


	

	public void deleteUrl(Url pUrl) {
		getUrlDAO().deleteUrl(pUrl);
	}

	public Url editUrl(Url pUrl) {
		return getUrlDAO().editUrl(pUrl);
	}

	public Map<Long, Url> getUrlSongIdMap(Set<Long> pUrlIds) {

		Map<Long, Url> songIdUrlMap = new HashMap<Long, Url>();
		List<Url> urls = getUrls(pUrlIds);
		for (Url url : urls) {
			songIdUrlMap.put(url.getSongId(), url);
		}
		return songIdUrlMap;
	}

	public List<Url> getUrls(Set<Long> pUrlIds) {
		return getUrlDAO().getUrls(pUrlIds);
	}
}
